<?php
$totalcash = 100;
$num = 1000;
$qhb_pool = array();
$leftcash = $totalcash*100 - 5*100;
$leftnum = $num;
for ($i=0;$i<1000;$i++)
{
	if ($i<50)
	{
		$cash = mt_rand(50,500);
	}else{
		$cash = mt_rand(1,100);
	}
	if (($leftcash-$cash)/($leftnum-1)<1)
	{
		$tempcash = 500 - (($leftnum-1) - ($leftcash-$cash));
		$cash = $cash + $tempcash;
		$qhb_pool[] = $cash;
		for ($n=0;$n<$leftnum-1;$n++)
		{
			$qhb_pool[] = 1;
		}
		break;
	}
	$qhb_pool[] = $cash;
	$leftcash -= $cash;
	$leftnum --;
}
foreach ($qhb_pool as $currcash)
{
	$re[] = $currcash/100;
}
var_dump($re);
var_dump(array_sum($re));
exit;
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_WARNING | E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING);
$dblink = getdblink_cl();
$sql = "select id from clsc.userinfo where regtype=7";
$res = exec_db_ps($sql,$dblink);
$i = 1;
while ($row = mysql_fetch_assoc($res))
{
	do {
		$sql = "select username from tttj.nick_pool where id=$i";
		$row2=getonerecord($sql);
		$i++;
	}while (!$row2);
	$id = $row['id']; 
	$username = $row2['username'];
	$sql = "update clsc.userinfo set username='$username' where id=$id";
	exec_db_ps($sql,$dblink);
}

echo $i.'OK';
exit;
collectnick();
function collectnick()
{
	include_once S_ROOT.'source/phpQuery1_0/phpQuery.php';
	for ($page = 1;$page<101;$page++)
	{
		$url="http://www.oicq88.com/nvsheng/$page.htm";
		$ref="http://www.oicq88.com/nvsheng/";
		$useragent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0";
		$timeout=10;
		$options=array(CURLOPT_REFERER=>$ref,CURLOPT_USERAGENT=>$useragent);
		$response=curl_get($url,$timeout,$options);
		if(!$response)
		{
			return false;
		}
		
		phpQuery::newDocumentHTML($response,'UTF-8');
		
		for ($i=1;$i<67;$i++)
		{
			$res_nick=trim(pq(".listfix .list p:eq($i)")->text());
			$res_nick=utftogbk($res_nick);
			$sql = "insert into nick_pool (username) values ('$res_nick')";
			try
			{
				exec_db_cj($sql);
			} catch (Exception $e) {
				continue;
			}
		}
	}
	
}

function exec_db_cj($query_str, $update =0) {
    $dblink = mysql_connect('127.0.0.1', 'gzy', 'kkizkkiz', 1, 131072);
    mysql_select_db('wysy');
    mysql_query("SET NAMES 'gbk'");
    $result = mysql_query($query_str);
    $rs = mysql_affected_rows();
    mysql_close($dblink);
    if ($update) {
        return $rs;
    } else {
        return $result;
    }
}
exit;
$time = time();
$sql = "select * from tttj.userinfo_robot limit 3000";
$tr = exec_db($sql);
$dblink = getdblink_cl();
while ($row = mysql_fetch_assoc($tr))
{
	$imei = $row['imei'];
	$ip = $row['ip'];
	$area = $row['area'];
	$logonum = rand(1,40);
	$logo = "http://a.cl.3z.cc/templates/images/user_pic/us_icon_{$logonum}.jpg";
	$pt = rand(1,2);
	$ontime = $time + rand(-100000,100000);
// 	$list[] = $row;
    $sql = "insert into clsc.userinfo (logo,ip,area,regtype,pt,ontime,last_login,appid) values ('$logo','$ip','$area','7','$pt',$ontime,$ontime,'110')";
    exec_db_ps($sql,$dblink);
//     echo $sql;
}
mysql_close($dblink);
echo 'ok';
exit;
function getdblink_cl() {
	$dblink = mysql_connect('127.0.0.1', 'gzy', 'kkizkkiz', 1, 131072) or die("Connect to db failed");
	mysql_select_db('clsc', $dblink);
	mysql_query("SET NAMES 'gbk'", $dblink);
	return $dblink;
}
require_once(S_ROOT."source/phpQuery1_0/phpQuery.php");
/*
 * ��ȡperiod
*/
//  http://1.163.com/win/getList.do?pageNum=1&pageSize=10&totalCnt=0&gid=140&period=303110802;
$total = 0;
$startindex = '';
$str='[{"period":"303110802","gid":"140"},{"period":"303110924","gid":"898"},{"period":"303110894","gid":"975"},{"period":"303110927","gid":"177"},{"period":"303110936","gid":"1093"},{"period":"303110871","gid":"896"},{"period":"303110835","gid":"148"},{"period":"303110921","gid":"510"},{"period":"303110879","gid":"139"},{"period":"303110906","gid":"897"},{"period":"303110856","gid":"992"},{"period":"303110800","gid":"137"},{"period":"303110752","gid":"349"},{"period":"303110919","gid":"895"},{"period":"303110900","gid":"116"},{"period":"303110859","gid":"145"},{"period":"303110639","gid":"1142"},{"period":"303110867","gid":"424"},{"period":"303110903","gid":"1061"},{"period":"303110316","gid":"946"},{"period":"303110526","gid":"330"},{"period":"303110585","gid":"347"},{"period":"303110787","gid":"1197"},{"period":"303110822","gid":"117"},{"period":"303110877","gid":"411"},{"period":"303110819","gid":"348"},{"period":"303110672","gid":"950"},{"period":"303110895","gid":"542"},{"period":"303110712","gid":"410"},{"period":"303110828","gid":"351"},{"period":"303110905","gid":"70"},{"period":"303110576","gid":"419"},{"period":"303110638","gid":"146"},{"period":"303110634","gid":"829"},{"period":"303110923","gid":"980"},{"period":"303110558","gid":"587"},{"period":"303110571","gid":"1413"},{"period":"303110833","gid":"437"},{"period":"303110342","gid":"360"},{"period":"303110577","gid":"443"},{"period":"303110937","gid":"976"},{"period":"303110711","gid":"1412"},{"period":"303110916","gid":"451"},{"period":"303110804","gid":"515"},{"period":"303110675","gid":"627"},{"period":"303110817","gid":"1323"},{"period":"303110744","gid":"564"},{"period":"303110777","gid":"1317"},{"period":"303110874","gid":"336"},{"period":"303110934","gid":"524"},{"period":"303110914","gid":"1588"},{"period":"303110907","gid":"1727"},{"period":"303110834","gid":"1310"},{"period":"303110513","gid":"352"},{"period":"303110891","gid":"1324"},{"period":"303110872","gid":"775"},{"period":"303110578","gid":"971"},{"period":"303110931","gid":"526"},{"period":"303110705","gid":"1439"},{"period":"303110642","gid":"1742"},{"period":"303110505","gid":"606"},{"period":"303110798","gid":"141"},{"period":"303110551","gid":"934"},{"period":"303110410","gid":"1450"},{"period":"303110870","gid":"194"},{"period":"303106271","gid":"1380"},{"period":"303110846","gid":"547"},{"period":"303110564","gid":"550"},{"period":"303110650","gid":"977"},{"period":"303105744","gid":"1194"},{"period":"303110910","gid":"509"},{"period":"303110875","gid":"119"},{"period":"303110760","gid":"1216"},{"period":"303105884","gid":"589"},{"period":"303110930","gid":"218"},{"period":"303110925","gid":"342"},{"period":"303104783","gid":"156"},{"period":"303105598","gid":"736"},{"period":"303110174","gid":"359"},{"period":"303110697","gid":"652"},{"period":"303110929","gid":"494"},{"period":"303110933","gid":"164"},{"period":"303110814","gid":"560"},{"period":"303110357","gid":"377"},{"period":"303110805","gid":"1212"},{"period":"303110791","gid":"485"},{"period":"303106272","gid":"1304"},{"period":"303110813","gid":"1726"},{"period":"303110920","gid":"569"},{"period":"303110759","gid":"931"},{"period":"303110836","gid":"375"},{"period":"303110451","gid":"978"},{"period":"303110886","gid":"591"},{"period":"303110815","gid":"335"},{"period":"303110832","gid":"1169"},{"period":"303110868","gid":"654"},{"period":"303110517","gid":"1589"},{"period":"303110917","gid":"219"},{"period":"303106323","gid":"1598"},{"period":"303110839","gid":"1294"},{"period":"303110530","gid":"669"},{"period":"303110876","gid":"552"},{"period":"303110890","gid":"1740"},{"period":"303110784","gid":"612"},{"period":"303110563","gid":"422"},{"period":"303105536","gid":"1592"},{"period":"303110765","gid":"438"},{"period":"303105990","gid":"735"},{"period":"303110560","gid":"216"},{"period":"303110693","gid":"226"},{"period":"303106072","gid":"483"},{"period":"303110541","gid":"1559"},{"period":"303105323","gid":"487"},{"period":"303110401","gid":"220"},{"period":"303110683","gid":"444"},{"period":"303110394","gid":"1151"},{"period":"303106328","gid":"1536"},{"period":"303110579","gid":"1361"},{"period":"303110808","gid":"432"},{"period":"303106380","gid":"812"},{"period":"303110904","gid":"160"},{"period":"303104245","gid":"1434"},{"period":"303110885","gid":"516"},{"period":"303110244","gid":"1311"},{"period":"303110446","gid":"964"},{"period":"303110408","gid":"1171"},{"period":"303103932","gid":"828"},{"period":"303110441","gid":"1422"},{"period":"303110758","gid":"768"},{"period":"303110509","gid":"1066"},{"period":"303110169","gid":"1440"},{"period":"303105227","gid":"1349"},{"period":"303110889","gid":"225"},{"period":"303110827","gid":"201"},{"period":"303110648","gid":"1572"},{"period":"303110755","gid":"770"},{"period":"303101711","gid":"357"},{"period":"303110818","gid":"1356"},{"period":"303110669","gid":"935"},{"period":"303110768","gid":"932"},{"period":"303110782","gid":"224"},{"period":"303100436","gid":"1594"},{"period":"303100965","gid":"1538"},{"period":"303110849","gid":"215"},{"period":"303110703","gid":"442"},{"period":"303110763","gid":"520"},{"period":"303110863","gid":"1712"},{"period":"303110749","gid":"475"},{"period":"303110643","gid":"1297"},{"period":"303110911","gid":"1587"},{"period":"303110716","gid":"200"},{"period":"303110654","gid":"128"},{"period":"303110901","gid":"611"},{"period":"303110440","gid":"1065"},{"period":"303110883","gid":"1441"},{"period":"303110820","gid":"134"},{"period":"303103926","gid":"1445"},{"period":"303110079","gid":"1321"},{"period":"303101645","gid":"441"},{"period":"303110570","gid":"517"},{"period":"303110614","gid":"531"},{"period":"303105830","gid":"1189"},{"period":"303110252","gid":"54"},{"period":"303103984","gid":"333"},{"period":"303110840","gid":"610"},{"period":"303110488","gid":"1548"},{"period":"303100904","gid":"1100"},{"period":"303110918","gid":"457"},{"period":"303105700","gid":"1714"},{"period":"303105476","gid":"665"},{"period":"303110584","gid":"1555"},{"period":"303110841","gid":"473"},{"period":"303102521","gid":"1401"},{"period":"303110617","gid":"549"},{"period":"303110771","gid":"1218"},{"period":"303110756","gid":"725"},{"period":"303103637","gid":"1593"},{"period":"303110842","gid":"541"},{"period":"303102593","gid":"1230"},{"period":"303110873","gid":"1409"},{"period":"303110893","gid":"940"},{"period":"303110884","gid":"1561"},{"period":"303110103","gid":"1590"},{"period":"303110753","gid":"702"},{"period":"303100950","gid":"1111"},{"period":"303106316","gid":"1235"},{"period":"303106318","gid":"358"},{"period":"303100629","gid":"769"},{"period":"303110472","gid":"827"},{"period":"303103431","gid":"1018"},{"period":"303110056","gid":"1295"},{"period":"303110773","gid":"534"},{"period":"303110850","gid":"1149"},{"period":"303110738","gid":"1219"},{"period":"303110913","gid":"459"},{"period":"303110666","gid":"1345"},{"period":"303105856","gid":"500"},{"period":"303110928","gid":"1546"},{"period":"303101049","gid":"1306"},{"period":"303110720","gid":"1716"},{"period":"303110908","gid":"446"},{"period":"303110514","gid":"1340"},{"period":"303110107","gid":"1213"},{"period":"303110659","gid":"1344"},{"period":"303110743","gid":"488"},{"period":"303106396","gid":"1319"},{"period":"303110843","gid":"1444"},{"period":"303110880","gid":"448"},{"period":"303110748","gid":"590"},{"period":"303105307","gid":"599"},{"period":"303110869","gid":"734"},{"period":"303110806","gid":"206"},{"period":"303110735","gid":"214"},{"period":"303105533","gid":"948"},{"period":"303105950","gid":"1309"},{"period":"303103257","gid":"1405"},{"period":"303110518","gid":"1308"},{"period":"303110780","gid":"1164"},{"period":"303110861","gid":"104"},{"period":"303110179","gid":"212"},{"period":"303110322","gid":"1564"},{"period":"303105087","gid":"1376"},{"period":"303110769","gid":"562"},{"period":"303110915","gid":"1166"},{"period":"303105245","gid":"1542"},{"period":"303110696","gid":"1563"},{"period":"303103734","gid":"1300"},{"period":"303102538","gid":"1047"},{"period":"303110695","gid":"1585"},{"period":"303110002","gid":"1557"},{"period":"303110926","gid":"1217"},{"period":"303104119","gid":"1552"},{"period":"303110702","gid":"1291"},{"period":"303103229","gid":"1407"},{"period":"303105997","gid":"1215"},{"period":"303091613","gid":"1397"},{"period":"303105857","gid":"1342"},{"period":"303110049","gid":"1214"},{"period":"303110622","gid":"421"},{"period":"303110888","gid":"651"},{"period":"303110083","gid":"726"},{"period":"303110750","gid":"105"},{"period":"303105981","gid":"1435"},{"period":"303105315","gid":"544"},{"period":"303110878","gid":"774"},{"period":"303071120","gid":"1223"},{"period":"303104850","gid":"518"},{"period":"303103288","gid":"1550"},{"period":"303105807","gid":"758"},{"period":"303110487","gid":"579"},{"period":"303110448","gid":"527"},{"period":"303110069","gid":"1549"},{"period":"303110717","gid":"831"},{"period":"303110047","gid":"1021"},{"period":"303110772","gid":"1720"},{"period":"303106223","gid":"1386"},{"period":"303110857","gid":"535"},{"period":"303103915","gid":"1393"},{"period":"303101006","gid":"1029"},{"period":"303110788","gid":"1731"},{"period":"303110899","gid":"213"},{"period":"303105988","gid":"1385"},{"period":"303110508","gid":"1547"},{"period":"303083518","gid":"1355"},{"period":"303105794","gid":"1497"},{"period":"303105248","gid":"1543"},{"period":"303105117","gid":"1307"},{"period":"303096472","gid":"1092"},{"period":"303105666","gid":"1446"},{"period":"303110837","gid":"1539"},{"period":"303110783","gid":"1044"},{"period":"303105562","gid":"1403"},{"period":"303106379","gid":"597"},{"period":"303110719","gid":"830"},{"period":"303110932","gid":"1348"},{"period":"303110881","gid":"1558"},{"period":"303110239","gid":"583"},{"period":"303106331","gid":"1447"},{"period":"303110178","gid":"1421"},{"period":"303101631","gid":"1527"},{"period":"303110797","gid":"1545"},{"period":"303104606","gid":"1287"},{"period":"303103919","gid":"1507"},{"period":"303085010","gid":"1228"},{"period":"303110492","gid":"1343"},{"period":"303110935","gid":"1475"},{"period":"303110185","gid":"458"},{"period":"303096495","gid":"1496"},{"period":"303110852","gid":"1443"},{"period":"303110912","gid":"1797"},{"period":"303103998","gid":"1463"},{"period":"303110291","gid":"1424"},{"period":"303110671","gid":"1433"},{"period":"303110520","gid":"1586"},{"period":"303105967","gid":"1465"},{"period":"303110909","gid":"1739"},{"period":"303081686","gid":"1482"},{"period":"303110922","gid":"1743"},{"period":"303085372","gid":"1504"},{"period":"303102722","gid":"989"},{"period":"303105972","gid":"988"},{"period":"303110465","gid":"1704"},{"period":"303110418","gid":"1597"},{"period":"303091417","gid":"1508"},{"period":"303110135","gid":"860"},{"period":"303110657","gid":"1423"},{"period":"303110779","gid":"1798"},{"period":"303096279","gid":"1511"},{"period":"303105293","gid":"1408"},{"period":"303105639","gid":"752"},{"period":"303110175","gid":"1056"},{"period":"303110041","gid":"755"},{"period":"303110770","gid":"933"},{"period":"303110652","gid":"1738"},{"period":"303110540","gid":"1722"},{"period":"303110799","gid":"1353"},{"period":"303110624","gid":"1208"},{"period":"303110792","gid":"1289"},{"period":"303105602","gid":"545"},{"period":"303110747","gid":"1762"},{"period":"303110938","gid":"1763"},{"period":"303106349","gid":"1799"},{"period":"303071019","gid":"1694"},{"period":"303110606","gid":"864"},{"period":"303110681","gid":"1579"},{"period":"303110006","gid":"1616"},{"period":"303110550","gid":"1705"},{"period":"303110858","gid":"1717"},{"period":"303110860","gid":"1710"},{"period":"303105594","gid":"1437"},{"period":"303105905","gid":"455"},{"period":"303094818","gid":"1505"},{"period":"303110010","gid":"1498"},{"period":"303100533","gid":"986"},{"period":"303101476","gid":"1387"},{"period":"303110887","gid":"1800"},{"period":"303110844","gid":"1357"},{"period":"303072847","gid":"1677"},{"period":"303104419","gid":"1318"},{"period":"303110692","gid":"1723"},{"period":"303076213","gid":"1525"},{"period":"303110699","gid":"754"},{"period":"303063069","gid":"1544"},{"period":"303110430","gid":"1809"},{"period":"303110477","gid":"1426"},{"period":"303110051","gid":"1360"},{"period":"303104177","gid":"1721"},{"period":"303104161","gid":"1432"},{"period":"303110090","gid":"1091"},{"period":"303105167","gid":"1520"},{"period":"303104301","gid":"1430"},{"period":"303090027","gid":"1334"},{"period":"303104118","gid":"1057"},{"period":"303096324","gid":"1513"},{"period":"303090278","gid":"1499"},{"period":"303110559","gid":"1637"},{"period":"303095367","gid":"1337"},{"period":"303110866","gid":"1718"},{"period":"303071323","gid":"1333"},{"period":"303095810","gid":"1650"},{"period":"303110732","gid":"1719"},{"period":"303101520","gid":"1669"},{"period":"303091030","gid":"1404"},{"period":"303110129","gid":"1431"},{"period":"303104805","gid":"1451"},{"period":"303105931","gid":"1622"},{"period":"303094915","gid":"1623"},{"period":"303102664","gid":"1473"},{"period":"303082123","gid":"1476"},{"period":"303045314","gid":"1541"},{"period":"303101680","gid":"1617"},{"period":"303110838","gid":"1752"},{"period":"303101150","gid":"1802"},{"period":"303101172","gid":"1803"},{"period":"303101385","gid":"1808"},{"period":"303105091","gid":"1603"},{"period":"303076214","gid":"1661"},{"period":"303074706","gid":"1611"},{"period":"303110392","gid":"772"},{"period":"303075348","gid":"1330"},{"period":"303051197","gid":"1518"},{"period":"303085408","gid":"1512"},{"period":"303110855","gid":"1750"},{"period":"303110317","gid":"1737"},{"period":"303101374","gid":"1807"},{"period":"303101237","gid":"1806"},{"period":"303101181","gid":"1804"},{"period":"303101228","gid":"1805"},{"period":"303065676","gid":"1672"},{"period":"303094714","gid":"1471"},{"period":"303094261","gid":"1402"},{"period":"303102217","gid":"1429"},{"period":"303110207","gid":"1708"},{"period":"303101538","gid":"1469"},{"period":"303103154","gid":"1578"},{"period":"303105424","gid":"1813"},{"period":"303070292","gid":"1646"},{"period":"303080947","gid":"1630"},{"period":"303096532","gid":"1688"},{"period":"303104087","gid":"1658"},{"period":"303096410","gid":"1632"},{"period":"303105446","gid":"1735"},{"period":"303053607","gid":"1540"},{"period":"303083602","gid":"1741"},{"period":"303101011","gid":"1628"},{"period":"303086423","gid":"1515"},{"period":"303104456","gid":"1666"},{"period":"303083774","gid":"1681"},{"period":"303102278","gid":"1618"},{"period":"303084370","gid":"1665"},{"period":"303090075","gid":"1642"},{"period":"303070961","gid":"1470"},{"period":"303091753","gid":"1667"},{"period":"303081452","gid":"1675"},{"period":"303081690","gid":"1680"},{"period":"303110862","gid":"1602"},{"period":"303073183","gid":"1620"},{"period":"303096430","gid":"1468"},{"period":"303104055","gid":"1691"},{"period":"303064473","gid":"1614"},{"period":"303110337","gid":"1811"},{"period":"303110882","gid":"1812"},{"period":"303052842","gid":"1653"},{"period":"303062210","gid":"1674"},{"period":"303074626","gid":"1474"},{"period":"303106246","gid":"1427"},{"period":"303061719","gid":"1673"},{"period":"303075746","gid":"1634"},{"period":"303090815","gid":"1643"},{"period":"303075387","gid":"1613"},{"period":"303105765","gid":"1749"},{"period":"303084158","gid":"1428"},{"period":"303110678","gid":"1745"},{"period":"303030973","gid":"1609"},{"period":"303093802","gid":"1747"},{"period":"303104227","gid":"1734"},{"period":"303094553","gid":"1381"},{"period":"303110825","gid":"1744"},{"period":"303110115","gid":"1751"},{"period":"303105912","gid":"1746"}]';
$arr=json_decode($str);
foreach($arr as $v)
{
	$list[]=(array)$v;
}
foreach($list as $value)
{
	$gid=$value['gid'];
	$period=$value['period'];
	$html=file_get_contents("http://1.163.com/record/getDuobaoRecord.do?gid=$gid&period=$period&pageSize=1000000&pageNum=1&totalCnt=0");
	if(!empty($html))
	{
		$json=json_decode($html,true);
		$result=$json["result"]["list"];
		if(!empty($result))
		{
			foreach($result as $value)
			{
				$username = $value['user']["nickname"];
				if($username)
				{
					$username=iconv("utf-8","gbk//IGNORE",$username);
					$ip=$value['user']["IP"];
					//add($username,$ip,$gid,$period);
					echo $username.'-'.$ip.' <br/>';
				}
			}
		}
	}
}
exit;
echo "�����ܹ�ץȡ<font style='color:red'> {$total} </font>����Ч��¼ | ��һ����¼ID = {$startindex} | ��һ����¼gid = {$gid} | ��һ����¼period = {$period} ";

function usernameFilter($username){
	$pattern = array('/@163.com/','/�ƹ�/','/ƭ/','/ƭ��/','/1Ԫ/','/һԪ/','/�ڸ�/','/����/','/����/','/��ʯ/','/������/','/ʯʯʯ/','/��/','/����/','/����/');
	$replace = array('@qq.com','�ᱦ','����','����','����','����','�ᱦ','�ᱦ','�ᱦ','����','������','�ᱦ��','��','�ᱦ','�ᱦ');
	$newname = preg_replace($pattern, $replace, $username);
	return $newname;
}

function add($username,$ip,$gid,$period)
{
	global $total;
	global $startindex;
	$name = usernameFilter($username);
	$name = str_replace(array('"',"'"," "),array('','',''),$name);
	$sql="select * from robot_ku where username='$name'";
	$row=getonerecord_robot($sql);
	if(!$row)
	{
		$sql="insert into robot_ku(username,ip) values('$name','$ip')";
		if($total == 0){
			$startindex = get_insert_id_robot($sql);
			$startgid = $gid;
			$startperiod = $period;
		}else{
			exec_db_robot($sql);
			$endgid = $gid;
			$endperiod = $period;
		}
		$total++;
	}
}

//echo addnewtask(153064,'newer_duobao');
?>